package juc.CAS;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntUnaryOperator;

public class test {
    public static void main(String[] args) {
        AtomicInteger a = new AtomicInteger(10);
        updateAndGet(a,p->p/2);
        System.out.println(a.get());
    }
    private static void updateAndGet(AtomicInteger a, IntUnaryOperator p) {
        while (true){
            int next = p.applyAsInt(a.get());
            if(a.compareAndSet(a.get(),next)){
                break;
            }
        }
    }
}
